package com.itao.spel;

import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

/**
 * @author sjt
 * @Date 2024/12/12 11:25
 */
public class Variables {

    public static void main(String[] args) {
        ExpressionParser parser = new SpelExpressionParser();
        EvaluationContext context = new StandardEvaluationContext();
        context.setVariable("primes1", Double.parseDouble("5"));
        context.setVariable("primes2", Double.parseDouble("15"));

        // Select all prime numbers > 10 from the list (using selection ?{...}).
        String expression = "#primes1 < #primes2 && #primes1 > #primes2";

            // Evaluates to a list containing [11, 13, 17].
        Boolean primesGreaterThanTen =
                parser.parseExpression(expression).getValue(context, Boolean.class);
        System.out.println(primesGreaterThanTen);
    }
}
